﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace Spelprojekt.Model
{
    class Menu
    {
        public enum MenuState
        {
            Main,            
            None
        }

        public MenuState m_menuState = MenuState.Main;

        //needs to always be changed just before m_menuState is changed
        private MenuState m_previousMenuState = MenuState.None;

        public Button[] m_buttons;

        public bool m_previousIsMouseDown = false;
        public bool m_isMouseDown = false;


        public void Update(float a_elapsedTime)
        {
            //if the menustate hasn't been changed
            if (m_previousMenuState == m_menuState)
            {

                //change previous mouse input
                if (m_isMouseDown == true)
                {
                    m_previousIsMouseDown = true;
                }
                else
                {
                    m_previousIsMouseDown = false;
                }
            }
            //if the menustate has been changed, load the new menu
            else
            {
                if (m_menuState == MenuState.Main)
                {
                    //set number of buttons
                    m_buttons = new Button[2];

                    //set buttons
                    Rectangle rect = new Rectangle(650, 300, 100, 25);
                    m_buttons[0] = new Button(rect, "Play", "PLAY");

                    Rectangle rect2 = new Rectangle(650, 350, 100, 25);
                    m_buttons[1] = new Button(rect2, "Exit", "EXIT");

                    //safety first
                    m_isMouseDown = false;
                    m_previousIsMouseDown = false;

                    //IMPORTANT
                    //change previous menu state state
                    m_previousMenuState = MenuState.Main;
                }
            }
        }

        //checks if a click has occurred
        public bool HasClicked()
        {
            if (m_isMouseDown == false && m_previousIsMouseDown == true)
            {
                return true;
            }

            return false;
        }

        //gets the button command (returns NULL if mousePosition wasn't inside a button)
        public string GetButtonCommand(Vector2 a_mousePosition)
        {
            foreach (Button button in m_buttons)
            {
                if (button.IsMouseOver(a_mousePosition))
                {
                    return button.m_command;
                }
            }

            return null;
        }
    }
}
